/*  1:   */ package nl.siegmann.epublib.bookprocessor;
/*  2:   */ 
/*  3:   */ import java.io.ByteArrayOutputStream;
/*  4:   */ import java.io.IOException;
/*  5:   */ import java.io.OutputStreamWriter;
/*  6:   */ import java.io.Writer;
/*  7:   */ import nl.siegmann.epublib.domain.Book;
/*  8:   */ import nl.siegmann.epublib.domain.Resource;
/*  9:   */ import nl.siegmann.epublib.epub.BookProcessor;
/* 10:   */ import nl.siegmann.epublib.util.NoCloseWriter;
/* 11:   */ import org.htmlcleaner.CleanerProperties;
/* 12:   */ import org.htmlcleaner.DoctypeToken;
/* 13:   */ import org.htmlcleaner.EpublibXmlSerializer;
/* 14:   */ import org.htmlcleaner.HtmlCleaner;
/* 15:   */ import org.htmlcleaner.TagNode;
/* 16:   */ import org.slf4j.Logger;
/* 17:   */ import org.slf4j.LoggerFactory;
/* 18:   */ 
/* 19:   */ public class HtmlCleanerBookProcessor
/* 20:   */   extends HtmlBookProcessor
/* 21:   */   implements BookProcessor
/* 22:   */ {
/* 23:32 */   private static final Logger log = LoggerFactory.getLogger(HtmlCleanerBookProcessor.class);
/* 24:   */   private HtmlCleaner htmlCleaner;
/* 25:   */   
/* 26:   */   public HtmlCleanerBookProcessor()
/* 27:   */   {
/* 28:37 */     this.htmlCleaner = createHtmlCleaner();
/* 29:   */   }
/* 30:   */   
/* 31:   */   private static HtmlCleaner createHtmlCleaner()
/* 32:   */   {
/* 33:41 */     HtmlCleaner result = new HtmlCleaner();
/* 34:42 */     CleanerProperties cleanerProperties = result.getProperties();
/* 35:43 */     cleanerProperties.setOmitXmlDeclaration(true);
/* 36:44 */     cleanerProperties.setOmitDoctypeDeclaration(false);
/* 37:45 */     cleanerProperties.setRecognizeUnicodeChars(true);
/* 38:46 */     cleanerProperties.setTranslateSpecialEntities(false);
/* 39:47 */     cleanerProperties.setIgnoreQuestAndExclam(true);
/* 40:48 */     cleanerProperties.setUseEmptyElementTags(false);
/* 41:49 */     return result;
/* 42:   */   }
/* 43:   */   
/* 44:   */   public byte[] processHtml(Resource resource, Book book, String outputEncoding)
/* 45:   */     throws IOException
/* 46:   */   {
/* 47:55 */     TagNode node = this.htmlCleaner.clean(resource.getReader());
/* 48:   */     
/* 49:   */ 
/* 50:58 */     node.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
/* 51:59 */     node.setDocType(createXHTMLDoctypeToken());
/* 52:   */     
/* 53:   */ 
/* 54:62 */     ByteArrayOutputStream out = new ByteArrayOutputStream();
/* 55:63 */     Writer writer = new OutputStreamWriter(out, outputEncoding);
/* 56:64 */     writer = new NoCloseWriter(writer);
/* 57:65 */     EpublibXmlSerializer xmlSerializer = new EpublibXmlSerializer(this.htmlCleaner.getProperties(), outputEncoding);
/* 58:66 */     xmlSerializer.write(node, writer, outputEncoding);
/* 59:67 */     writer.flush();
/* 60:   */     
/* 61:69 */     return out.toByteArray();
/* 62:   */   }
/* 63:   */   
/* 64:   */   private DoctypeToken createXHTMLDoctypeToken()
/* 65:   */   {
/* 66:73 */     return new DoctypeToken("html", "PUBLIC", "-//W3C//DTD XHTML 1.1//EN", "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd");
/* 67:   */   }
/* 68:   */ }


/* Location:           C:\Users\David\workspace\CosaRaraPorqueSi\main\epublib-tools-3.1.jar
 * Qualified Name:     nl.siegmann.epublib.bookprocessor.HtmlCleanerBookProcessor
 * JD-Core Version:    0.7.0.1
 */